﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IList<BA2009.Entities.Resource>>" %>
<%@ Import Namespace="MvcContrib.UI.Grid" %>
<%@ Import Namespace="MvcContrib.UI.Grid.ActionSyntax" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Search
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Search</h2>
    
    <script type="text/javascript">

        var oTable;
        $(document).ready(function() {

           oTable= $('#search_datatable').dataTable(
        {
            "fnRowCallback": function(nRow, aData, iDisplayIndex) {
                // Deal with a click on each row
                $(nRow).click(function() {
                    // Check if we are adding or removing a row
                    if (aData[5] == 1) {
                        aData[5] = 0;
                    }
                    else {
                        aData[5] = 1;
                    }

                    // Change the class based on selection
                    this.className = (aData[5] == 1) ?
                        this.className + '_selected' : this.className.replace(/_selected/, "");
                }
                );

                /* For each draw - set the class based on the stored data */
                nRow.className = (aData[5] == 1) ?
				nRow.className + '_selected' :
			 	nRow.className.replace(/_selected/, "");

                return nRow;

            }
        }
        );
        }
        );


        function fnGetSelected(oTableLocal) {
            var aSelected = new Array();
            var aaData = oTableLocal.fnSettings().aaDataMaster;
            for (var i = 0; i < aaData.length; i++) {
                if (aaData[i][5] == 1) {
                    aSelected.push(aaData[i][0]);
                }
            }

            return aSelected;
        }
    </script>
    
    <style type="text/css">
        #search_datatable{width:100%}
        #search_container{width:600px}
    </style>
    
    <div id="search_container">
    <% Html.Grid(Model).Columns(column =>
           {
               column.For(c => c.ResourceID).Named("ResourceID").Visible(false);
               column.For(c => c.Code).Named("Mã");
               column.For(c => c.FileName).Named("Tên file");
               column.For(c => c.Description).Named("Miêu tả");
           })
           .Attributes(id => "search_datatable")
           .Render();
                     
            %>
    </div>
</asp:Content>
